{{template "shared/bootstrap_table_js.html"}}
<script>
    var $dataGrid = $('#dataGrid');
    var $searchForm = $("#searchForm");

    var highlightPk = 0;

    $(function () {
        pageInit()
    });

    function pageInit() {
        dataGridInit()
    }

    function dataGridInit() {
        $dataGrid.bootstrapTable({
            url: '{{urlfor "NotificationController.DataGrid"}}',
            method: 'post',
            sidePagination: 'server',
            idField: 'Id',
            queryParamsType: 'limit',
            queryParams: function (params) {
                params.Title = $.trim($('.searchForm input[name="Title"]').val());
                return params
            },
            pagination: true,
            showRefresh: true,
            showColumns: true,
            toolbar: '#toolbar',
            pageSize: 10,
            pageList: [5, 10, 20, 100, 200],
            paginationShowPageGo: true,//20170812 lht 扩展select跳转
            paginationUseBSSelect: true,//20170812 lht 扩展select跳转 启用BoostrapSelect(页面须引用botstrap-select.min.js)
            cookie: true,
            classes: 'table table-bordered table-hover',
            undefinedText: '',
            sortName: 'Id',
            sortOrder: 'desc',
            stickyHeader: true,
            resizable: true,

            rowAttributes: function (row, index) {
                return {'data-pk': row.Id}
            },
            columns: [{
                field: 'state',
                checkbox: true,
                radio: false
            }, {
                field: 'Id',
                title: 'ID',
                width: '80px',
                align: 'center',
                sortable: true
            }, {
                field: 'Title',
                title: '标题',
                align: 'center'
            }, {
                field: 'CreateAt',
                title: '添加时间',
                align: 'center',
                formatter: function (value, row, index) {
                    return new Date(value * 1000).format('yyyy-MM-dd hh:mm:ss')
                }
            }, {
                field: 'IfSchedule',
                title: '是否定时发布',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '否';
                    }
                    return '是'
                }
            }, {
                field: 'SendTime',
                title: '发布时间',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value > 0) {
                        return new Date(value * 1000).format('yyyy-MM-dd hh:mm:ss')
                    }
                    return '未发布';
                }
            }, {
                field: 'CancelTime',
                title: '撤回时间',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value > 0) {
                        return new Date(value * 1000).format('yyyy-MM-dd hh:mm:ss')
                    }
                    return '未撤回';
                }
            }, {
                field: 'DeleteTime',
                title: '删除时间',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value > 0) {
                        return new Date(value * 1000).format('yyyy-MM-dd hh:mm:ss')
                    }
                    return '未删除';
                }
            }, {
                field: 'operator',
                title: '操作',
                align: 'center',
                width: '250px',
                formatter: function (value, row, index) {
                    var html = [];
                    html.push('<div class="btn-group">');
                    if ('{{.canEdit}}' === 'true') {
                        html.push('<button class="btn btn-primary btn-xs" onclick="EditFun(' + row.Id + ')"><i class="fa fa-pencil"></i> 编辑</button>');
                    }
                    html.push('</div>');
                    return html.join('')
                }
            }],
            onLoadSuccess: function (data) {
                layer.closeAll('loading')
            },
            onSort: function (name, order) {

            },
            onCheckAll: function (rows) {
                $(".table-btn-check-enable").removeAttr("disabled")
            },
            onCheck: function (rows) {
                $(".table-btn-check-enable").removeAttr('disabled');
            },
            onUncheck: function (rows) {
                if ($("#dataGrid").bootstrapTable("getSelections").length === 0) {
                    $(".table-btn-check-enable").attr('disabled', 'disabled');
                }
            },
            onUncheckAll: function () {
                //禁用删除需要勾选才能用的按钮
                if ($("#dataGrid").bootstrapTable("getSelections").length === 0) {
                    $(".table-btn-check-enable").attr('disabled', 'disabled');
                }
            },
            onLoadError: function (status) {
                layer.alert('获取数据失败,错误代码：' + status);
            }
        });
    }

    function EditFun(Id) {
        var title = "添加消息";
        if (Id > 0) {
            title = "编辑消息"
        }
        var url = '{{urlfor "NotificationController.Edit"}}/' + Id;
        layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            shade: 0.2,
            maxmin: true,
            shift: 1,
            area: ['1000px', '600px'],
            content: url,
            btn: ['保存', '关闭'],
            yes: function (index, layerNo) {
                var iFrameWin = window[layerNo.find('iframe')[0]['name']];
                iFrameWin.FormSubmit();
            }
        })
    }

    function DeleteFun(Id) {

    }

    function refresh(pk) {
        $dataGrid.bootstrapTable('refresh');
        highlightPk = pk;
    }
</script>